﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Vds2465Telegrams
{
    [TestClass]
    public class Telegram_Calling_Test
    {
        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test01_Equals()
        {
            Telegram_Calling telegramCalling = new Telegram_Calling(eDirection.ATE_to_RCT, 0x57, eTelegramFunction_Calling.REQ_NDAT, true, false);
            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(telegramCalling.Equals(dummyObject));
            }

            {
                // equal
                Telegram_Calling telegramCalling2Compare = new Telegram_Calling(telegramCalling.Direction, telegramCalling.Address,
						telegramCalling.TelegramFunction, telegramCalling.FrameCountValid, telegramCalling.FrameCountFlag);
                Assert.IsTrue(telegramCalling.Equals(telegramCalling2Compare));
            }

            {
                // direction differs - NOT equal
				eDirection direction;
				if (telegramCalling.Direction == eDirection.ATE_to_RCT)
                {
					direction = eDirection.RCT_to_ACE;
                }
                else
                {
					direction = eDirection.ATE_to_RCT;
                }

				Telegram_Calling telegramCalling2Compare = new Telegram_Calling(direction, telegramCalling.Address, telegramCalling.TelegramFunction, 
					telegramCalling.FrameCountValid, telegramCalling.FrameCountFlag);
                Assert.IsFalse(telegramCalling.Equals(telegramCalling2Compare));
            }

            {
                // address differs - NOT equal
				Telegram_Calling telegramCalling2Compare = new Telegram_Calling(telegramCalling.Direction, (byte) (telegramCalling.Address - 1),
					telegramCalling.TelegramFunction, telegramCalling.FrameCountValid, telegramCalling.FrameCountFlag);                
                Assert.IsFalse(telegramCalling.Equals(telegramCalling2Compare));
            }

            {
                // function differs - NOT equal
				eTelegramFunction_Calling telegramFunctionCalling;
				if (telegramCalling.TelegramFunction == eTelegramFunction_Calling.REQ_NDAT)
				{
					telegramFunctionCalling = eTelegramFunction_Calling.SEND_NDAT;
				}
				else
				{
					telegramFunctionCalling = eTelegramFunction_Calling.REQ_NDAT;
				}
				Telegram_Calling telegramCalling2Compare = new Telegram_Calling(telegramCalling.Direction, telegramCalling.Address,
					telegramFunctionCalling, telegramCalling.FrameCountValid, telegramCalling.FrameCountFlag);              
                Assert.IsFalse(telegramCalling.Equals(telegramCalling2Compare));
            }

            {
                // FrameCountFlag differs - NOT equal
				Telegram_Calling telegramCalling2Compare = new Telegram_Calling(telegramCalling.Direction, telegramCalling.Address,
					telegramCalling.TelegramFunction, telegramCalling.FrameCountValid, !telegramCalling.FrameCountFlag);
                Assert.IsFalse(telegramCalling.Equals(telegramCalling2Compare));
            }

            {
                // FrameCountValid differs - NOT equal
				Telegram_Calling telegramCalling2Compare = new Telegram_Calling(telegramCalling.Direction, telegramCalling.Address,
					telegramCalling.TelegramFunction, !telegramCalling.FrameCountValid, telegramCalling.FrameCountFlag);
                Assert.IsFalse(telegramCalling.Equals(telegramCalling2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test02_GetHashCode()
        {
            Telegram_Calling telegramCalling = new Telegram_Calling(eDirection.ATE_to_RCT, 0x57,
				eTelegramFunction_Calling.REQ_NDAT, true, false);
            int hashCode01 = telegramCalling.GetHashCode();
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test03_ToString()
        {
			Telegram_Calling telegramCalling = new Telegram_Calling(eDirection.ATE_to_RCT, 0x57, eTelegramFunction_Calling.REQ_NDAT, true, false);
            string string01 = telegramCalling.ToString();
            Assert.IsNotNull(string01);            
        }
    }
}
